//
//  RootViewController.m
//  TableViewPull
//
//  Created by Devin Doty on 10/16/09October16.
//  Copyright enormego 2009. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

#import "PBLViewController.h"
#import "ASIHTTPRequest.h"
#import "CJSONDeserializer.h"
#import "pblasyncimageview.h"
#import "GCDiscreetNotificationView.h"
#import "TZDetailViewController.h"
#import "MainTabBarController.h"
#import "CollectListViewController.h"
#import "OwnViewController.h"
#import "LoginViewController.h"
#import "AddAlbumViewController.h"
#import "AppDelegate.h"
#import "TZScrollViewController.h"

#define WidthMax 145.f //瀑布流一元素宽
#define LineDis 10 //瀑布流间隙
#define TextH  83 //文本高度
#define PageSize 10  //页取数据
#define CollectH 180 //专辑总高
#define CollectLineH 10 //专辑间隙高
#define UserCellH 42 //人儿一行高
static int s_FloderIndex = 0;
@implementation PBLViewController
@synthesize m_RquestURL;
@synthesize m_NowModeType;
@synthesize m_SuperNavVC;
//@synthesize m_ShowUserID;
-(id) init
{
    if (self = [super init]) {
        _ContentDicArr = [[NSMutableArray alloc] init];
        _ViewsArr = [[NSMutableArray alloc] init];
        _SearchContentDicArr= [[NSMutableArray alloc] init];;//数据
        _SearchViewsArr= [[NSMutableArray alloc] init];;//试图数据
        _LeftH = 10;
        _RightH = 10;
        _NowPageIndex =0;
        _IsRequesting =NO;
        _IsSearchRequesting = NO;
        _searchStatus =NO;
        _SearchFuncationOpen = NO;
        _MaxID =@"0";
        [_MaxID retain];
        
        NSString* tTemp = NSTemporaryDirectory();
        _TempFloderName =[NSString stringWithFormat:@"pbltemp%d",s_FloderIndex];
        [_TempFloderName retain];
        _FloderIndex = s_FloderIndex;
        s_FloderIndex++;
        NSString *fileName=[tTemp stringByAppendingPathComponent:_TempFloderName];
        NSFileManager* tFileManager = [NSFileManager defaultManager];
        NSError* tError = nil;
        if ([tFileManager fileExistsAtPath:fileName]) {
            [tFileManager removeItemAtPath:fileName error:&tError];
        }
        [tFileManager createDirectoryAtPath:fileName withIntermediateDirectories:NO attributes:nil error:&tError];
        _BottomNot = [[GCDiscreetNotificationView alloc] init];
        [_BottomNot setShowActivity:YES];
        [_BottomNot setPresentationMode:GCDiscreetNotificationViewPresentationModeBottom];
        
        
        _CommentZC =[UIImage imageNamed:@"icon_forward.png"];
        _CommentFav=[UIImage imageNamed:@"icon_like.png"];
        _CommentPL=[UIImage imageNamed:@"icon_comment.png"];
        _UserIcon = [UIImage imageNamed:@"userIcon.png"];
        _CommentRedFav = [UIImage imageNamed:@"icon_like_red"];
        [_CommentZC retain];
        [_CommentFav retain];
        [_CommentPL retain];
        [_UserIcon retain];
        [_CommentRedFav retain];
    }
    return self;
}

#pragma mark -
#pragma mark Memory Management

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    int tShowH = _ContentScrollView.contentOffset.y+_ContentScrollView.frame.size.height;
    for (int i =0; i<[_ViewsArr count];i++) {
        PBLAsyncImageView* tAsyImg = [_ViewsArr objectAtIndex:i];
        if ((tAsyImg.frame.origin.y > tShowH || tAsyImg.frame.origin.y+tAsyImg.frame.size.height < tShowH-480) && tAsyImg._numStateRequested == suc_Request) {
            [tAsyImg getInImageView].image =nil;
            [tAsyImg.m_ImageBuffer release];
            tAsyImg.m_ImageBuffer = nil;
        }
    }
}

- (void)viewDidUnload {
    [_refreshHeaderView release];
	_refreshHeaderView=nil;
}

- (void)dealloc {
    NSString* tTemp = NSTemporaryDirectory();
    NSString *fileName=[tTemp stringByAppendingPathComponent:_TempFloderName];
    NSFileManager* tFileManager = [NSFileManager defaultManager];
    NSError* tError = nil;
    if ([tFileManager fileExistsAtPath:fileName]) {
        [tFileManager removeItemAtPath:fileName error:&tError];
        NSLog(@"%@",[tError description]);
    }
    
    if (_SearchTempFName != nil) {
        NSString *searchfileName=[tTemp stringByAppendingPathComponent:_SearchTempFName];
        if ([tFileManager fileExistsAtPath:searchfileName]) {
            [tFileManager removeItemAtPath:searchfileName error:&tError];
            NSLog(@"%@",[tError description]);
        }
    }
    [_CollectUserIDStr release];
    [_CommentRedFav release];
    [_TopStatusView release];
//    [m_ShowUserID release];
    [_MaxID release];
    [m_RquestURL release];
    [_TempFloderName release];
    [_BottomNot release];
    [_PBLRequest cancel];
    [_PBLRequest setDelegate:nil];
    [_PBLRequest release];
    _PBLRequest=nil;
    [_ViewsArr release];
    [_ContentDicArr release];
    [_ContentScrollView release];
    [_refreshHeaderView release];
	_refreshHeaderView = nil;
    [_SearchView release];
    [_SearchTypeStr release];
    [_CommentZC release];
    [_CommentFav release];
    [_CommentPL release];
    [_UserIcon release];
    //搜索释放
    [_SearchContentDicArr release];//数据
    [_SearchViewsArr release];//试图数据
    [_SearchTempFName release];
    [_SearchContentSView removeFromSuperview];
    [_SearchContentSView release];
    [_TieZiSearchDic release];//贴子的结果
    [_CollectSearchDic release];//专辑
    [_RenErSearchDic release];//人儿
    [_SearchKeyWord release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    if (Mode_Type_ShortInfoShow == m_NowModeType) {
        self.view.frame =CGRectMake(0, 128, 320, 480-20-44-128-49);
    }else if (Mode_Type_InfoShow == m_NowModeType) {
        self.view.frame =CGRectMake(0, 128, 320, 480-20-44-128);
    }else if(Mode_Type_CollectList == m_NowModeType){
        self.view.frame =CGRectMake(0, 0, 320, 480-20-44);
    }
    
    [_ContentScrollView release];
    _ContentScrollView =nil;
    if (Mode_Type_ShortInfoShow == m_NowModeType) {
        _ContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-20-44-128-49)];
        _ContentScrollView.contentSize =CGSizeMake(320, 480-20-43-49-128-49);
    }else if (Mode_Type_InfoShow == m_NowModeType) {
        _ContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-20-44-128)];
        _ContentScrollView.contentSize =CGSizeMake(320, 480-20-43-49-128);
    }else if(Mode_Type_CollectList == m_NowModeType){
        _ContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, 320, 480-20-44-49-44)];
        _ContentScrollView.contentSize =CGSizeMake(320, 480-20-43-49-44);
        
    }else{
        _ContentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-20-44-49)];
        _ContentScrollView.contentSize =CGSizeMake(320, 480-20-43-49);
    }
    _ContentScrollView.delegate = self;
    [self.view addSubview:_ContentScrollView];
    
    if (Mode_Type_CollectList == m_NowModeType) {
        _TopStatusView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
        [_TopStatusView setBackgroundColor:[UIColor whiteColor]];
        [self.view addSubview:_TopStatusView];
        UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
        tImgView.frame =CGRectMake(0, 44, 320, 5);
        [_TopStatusView addSubview:tImgView];
        [tImgView release];
    }
    
    [_refreshHeaderView release];
    _refreshHeaderView =nil;
    _refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.view.bounds.size.height, self.view.frame.size.width, self.view.bounds.size.height)];
    _refreshHeaderView.delegate = self;
    [_ContentScrollView addSubview:_refreshHeaderView];
	
	//  update the last update date
	[_refreshHeaderView refreshLastUpdatedDate];
    
}

-(void) firstDataGet
{
    [self addHudLoad];
    _NowPageIndex = 0;
    _BFPageIndex = _NowPageIndex;
    _NowPageIndex = 0;
    [_MaxID release];
    _MaxID =@"0";
    [_MaxID retain];
    _LeftH = 10;
    _RightH = 10;
    [self clearAllBuffFile];
    [self requestPageData];
}

//下拉清除所有缓存
-(void) clearAllBuffFile
{

    NSString* tTemp = NSTemporaryDirectory();
    NSString *fileName=[tTemp stringByAppendingPathComponent:_TempFloderName];
    NSFileManager* tFileManager = [NSFileManager defaultManager];
    NSError* tError = nil;
    if ([tFileManager fileExistsAtPath:fileName]) {
        [tFileManager removeItemAtPath:fileName error:&tError];
        NSLog(@"%@",[tError description]);
    }
    
    NSString *filecName=[tTemp stringByAppendingPathComponent:_TempFloderName];
    if ([tFileManager fileExistsAtPath:filecName]) {
        [tFileManager removeItemAtPath:filecName error:&tError];
    }
    [tFileManager createDirectoryAtPath:filecName withIntermediateDirectories:NO attributes:nil error:&tError];
    
    [_ContentDicArr removeAllObjects];
    [_ViewsArr removeAllObjects];
    
    for (id subObject in _ContentScrollView.subviews) {
        if (![subObject isKindOfClass:[EGORefreshTableHeaderView class]]) {
            [subObject removeFromSuperview];
        }
    }
}

//-(void)UserDetailFinish:(ASIHTTPRequest*)request
//{
//    NSError* tError;
//    
//    NSString* tReqStr = [request responseString];
//    NSLog(@"ads json data =%@",tReqStr);
//    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
//	NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
//    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
//    if (tDictionary == nil) {
//        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
//        [self hudWasHidden:nil];
//        [_PBLRequest setDelegate:nil];
//        [_PBLRequest release];
//        _PBLRequest= nil;
//        [_BottomNot hide:YES];
//        return;
//    }
//    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
//    if (tErrorCode != 0) {
//        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
//        [self hudWasHidden:nil];
//        [_PBLRequest setDelegate:nil];
//        [_PBLRequest release];
//        _PBLRequest= nil;
//        [_BottomNot hide:YES];
//        return;
//    }
//    NSDictionary* tDataDic =[tDictionary objectForKey:@"data"];
//    AsyncImageView* tAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(6, 9, 26, 26)];
//    tAsyImg.m_BoolSetImage =YES;
//    tAsyImg._imageRequestURL = [tDataDic objectForKey:@"avatar"];
//    tAsyImg._numStateRequested = need_Request;
//    [_TopStatusView addSubview:tAsyImg];
//    [tAsyImg customLoadImageFromURL];
//    [tAsyImg release];
//    
//    UILabel* tNameLab =[[UILabel alloc] initWithFrame:CGRectMake(40, 6, 200, 18)];
//    [tNameLab setBackgroundColor:[UIColor clearColor]];
//    [tNameLab setFont:[UIFont boldSystemFontOfSize:15]];
//    [tNameLab setText:[tDataDic objectForKey:@"nickname"]];
//    [_TopStatusView addSubview:tNameLab];
//    [tNameLab release];
//    
//    
//    UILabel* tDesLab =[[UILabel alloc] initWithFrame:CGRectMake(40, 24, 200, 16)];
//    [tDesLab setBackgroundColor:[UIColor clearColor]];
//    [tDesLab setTextColor:[UIColor lightGrayColor]];
//    [tDesLab setFont:[UIFont systemFontOfSize:16]];
//    [tDesLab setText:[tDataDic objectForKey:@"user_nickname"]];
//    [_TopStatusView addSubview:tDesLab];
//    [tDesLab release];
//    
//    [self hudWasHidden:nil];
//}

//-(void)UserDetailFail:(ASIHTTPRequest*)request
//{
//    [self hudWasHidden:nil];
//    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
//    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
//}

-(void) requestPageData
{
    if (_PBLRequest == nil && !_IsRequesting) {
        _IsRequesting =YES;
        if (_MaxID == nil || [_MaxID isKindOfClass:[NSNull class]]) {
            [_MaxID release];
            _MaxID = @"0";
            [_MaxID retain];
        }
        _NowPageIndex++;
        NSURL* tRequestURL = nil;
        if (m_NowModeType == Mode_Type_Attention||m_NowModeType == Mode_Type_RecommendOrNew) {
            [self initSearchView];//有搜索部分
            NSString* tUserID =nil;
            if(m_NowModeType == Mode_Type_RecommendOrNew){
                MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
                tUserID =[tMainTabBar.m_UserDic objectForKey:@"user_id"];
            }
            if ([tUserID length] > 0) {
                tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@&page=%d&limit=%d&max_id=%@&user_id=%@",m_RquestURL,_NowPageIndex,PageSize,_MaxID,tUserID]];
            }else{
                tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@&page=%d&limit=%d&max_id=%@",m_RquestURL,_NowPageIndex,PageSize,_MaxID]];
            }
            
        }else if(m_NowModeType ==Mode_Type_CollectList){//有抬头
            tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@&page=%d&limit=%d&max_id=%@",m_RquestURL,_NowPageIndex,PageSize,_MaxID]];
        }else if(m_NowModeType ==Mode_Type_InfoShow|| Mode_Type_ShortInfoShow== m_NowModeType){//信息里的
            tRequestURL =[NSURL URLWithString:[NSString stringWithFormat:@"%@&page=%d&limit=%d",m_RquestURL,_NowPageIndex,PageSize]];
        }
        
        _PBLRequest = [ASIHTTPRequest requestWithURL:tRequestURL];
        [_PBLRequest setDelegate:self];
        [_PBLRequest startAsynchronous];
        [_PBLRequest retain];
    }
}

- (void)requestFinished:(ASIHTTPRequest *)request;
{
    NSError* tError;
    
    NSString* tReqStr = [request responseString];
    NSLog(@"ads json data =%@",tReqStr);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
	NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [_PBLRequest setDelegate:nil];
        [_PBLRequest release];
        _PBLRequest= nil;
        [_BottomNot hide:YES];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [_PBLRequest setDelegate:nil];
        [_PBLRequest release];
        _PBLRequest= nil;
        [_BottomNot hide:YES];
        return;
    }

    NSArray* tDicArr =nil;
    if (Mode_Type_CollectList== m_NowModeType) {
        tDicArr =[[tDictionary objectForKey:@"data"] objectForKey:@"list"];
        
        //抬头
        NSDictionary* tDataDic =[tDictionary objectForKey:@"data"];
        AsyncImageView* tAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(6, 9, 26, 26)];
        tAsyImg.m_BoolSetImage =YES;
        tAsyImg._imageRequestURL = [tDataDic objectForKey:@"user_avatar"];
        tAsyImg._numStateRequested = need_Request;
        [_TopStatusView addSubview:tAsyImg];
        [tAsyImg customLoadImageFromURL];
        [tAsyImg release];
        
        [_CollectUserIDStr release];
        _CollectUserIDStr =nil;
        _CollectUserIDStr = [tDataDic objectForKey:@"user_id"];
        [_CollectUserIDStr retain];
        
        UIButton* tHeadBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tHeadBtt.frame =tAsyImg.frame;
        [tHeadBtt addTarget:self action:@selector(headPressed) forControlEvents:UIControlEventTouchUpInside];
        [_TopStatusView addSubview:tHeadBtt];
        
        UILabel* tNameLab =[[UILabel alloc] initWithFrame:CGRectMake(40, 6, 200, 18)];
        [tNameLab setBackgroundColor:[UIColor clearColor]];
        [tNameLab setFont:[UIFont boldSystemFontOfSize:12]];
        [tNameLab setText:[tDataDic objectForKey:@"user_nickname"]];
        [_TopStatusView addSubview:tNameLab];
        [tNameLab release];
        
        
        UILabel* tDesLab =[[UILabel alloc] initWithFrame:CGRectMake(40, 23, 200, 16)];
        [tDesLab setBackgroundColor:[UIColor clearColor]];
        [tDesLab setTextColor:[UIColor lightGrayColor]];
        [tDesLab setFont:[UIFont systemFontOfSize:11]];
        [tDesLab setText:[NSString stringWithFormat:@"%@   %@",[tDataDic objectForKey:@"name"],[tDataDic objectForKey:@"blog_count"]]];
        [_TopStatusView addSubview:tDesLab];
        [tDesLab release];
    }else{
        tDicArr =[[tDictionary objectForKey:@"data"] objectForKey:@"list"];
        if (m_NowModeType == Mode_Type_Attention && [tDicArr count] == 0) {
            _LeftH =0;
            _RightH = 0;
            [self clearAllBuffFile];
            [self performSelector:@selector(ShowTipView)];
        }
    }
    
    [_MaxID release];
    _MaxID =nil;
    if (Mode_Type_CollectList== m_NowModeType) {
        _MaxID = @"0";
        [_MaxID retain];
    }else{
        _MaxID = [[tDictionary objectForKey:@"data"] objectForKey:@"max_id"];
        [_MaxID retain];
    }
    
    
    int tBttTag = [_ContentDicArr count];
    [_ContentDicArr addObjectsFromArray:tDicArr];
    
    

    
    int tWidth = 0;
    int tHeight = 0;
    float tScaleIndex = 0.f;
    UIImage* tLeftBGImg = [UIImage imageNamed:@"block_shadow_left.png"];
    UIImage* tRightBGImg = [UIImage imageNamed:@"block_shadow_right.png"];
    UIImage* tTopBGImg = [UIImage imageNamed:@"block_shadow_top.png"];
    UIImage* tBottomBGImg = [UIImage imageNamed:@"block_shadow_bottom.png"];
    for (NSDictionary* tInDic in tDicArr) {
        UIButton* tCustomBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tCustomBtt.tag = tBttTag;
        [tCustomBtt addTarget:self action:@selector(bttToDetail:) forControlEvents:UIControlEventTouchUpInside];
        
        tWidth = [[tInDic objectForKey:@"image_width"] intValue];
        tHeight = [[tInDic objectForKey:@"image_height"] intValue];
        tScaleIndex = WidthMax/tWidth;
        tHeight = tHeight*tScaleIndex;
        
        int tOffsetHeight = 0;//add by Scott
        if ([[tInDic objectForKey:@"description"] isEqualToString:@""]) {
            tOffsetHeight = 0;
        } else {
            if ([[tInDic objectForKey:@"description"] length] > 11) {
                tOffsetHeight = 30;
            } else {
                tOffsetHeight = 18;
            }
        }

        int tCheckPos = 0;
        int tCheckValue = _LeftH;
        if (tCheckValue > _RightH) {
            tCheckPos =2;
        }
        PBLAsyncImageView* tAsyImg = nil;
        switch (tCheckPos) {
            case 0://左
            {
                tAsyImg = [[PBLAsyncImageView alloc] initWithFrame:CGRectMake(10, _LeftH, WidthMax, tHeight)];
                tCustomBtt.frame =CGRectMake(10, _LeftH, WidthMax, tHeight+TextH+tOffsetHeight);
                _LeftH+=tHeight+LineDis+TextH+tOffsetHeight;
            }
                break;
            case 2://右
            {
                tAsyImg = [[PBLAsyncImageView alloc] initWithFrame:CGRectMake(165, _RightH, WidthMax, tHeight)];
                tCustomBtt.frame =CGRectMake(165, _RightH, WidthMax, tHeight+TextH+tOffsetHeight);
                _RightH+=tHeight+LineDis+TextH+tOffsetHeight;
            }
                break;
        }
        [tAsyImg setBackgroundColor:[UIColor colorWithRed:183/255.f green:185/255.f blue:183/255.f alpha:1.0]];
        
        NSString* tImgURL =[tInDic objectForKey:@"image"];
        tAsyImg._imageRequestURL =tImgURL;
        tAsyImg._numStateRequested =need_Request;
        tAsyImg.m_BoolSetImage =YES;
        tAsyImg.m_FloderIndex = _FloderIndex;
        tAsyImg.m_AsyTag = tBttTag;
        
        [_ContentScrollView addSubview:tAsyImg];
        [_ContentScrollView addSubview:tCustomBtt];
        [tAsyImg release];
        
        UIImageView* tTopShadow = [[UIImageView alloc] initWithImage:tTopBGImg];
        tTopShadow.frame =CGRectMake(tAsyImg.frame.origin.x, tAsyImg.frame.origin.y-2, tAsyImg.frame.size.width, 2);
        [_ContentScrollView addSubview:tTopShadow];
        [tTopShadow release];
        
        UIImageView* tBottomShadow = [[UIImageView alloc] initWithImage:tBottomBGImg];
        tBottomShadow.frame =CGRectMake(tAsyImg.frame.origin.x, tAsyImg.frame.origin.y+tHeight+TextH+tOffsetHeight, tAsyImg.frame.size.width, 2);
        [_ContentScrollView addSubview:tBottomShadow];
        [tBottomShadow release];
        
        UIImageView* tLeftShadow = [[UIImageView alloc] initWithImage:tLeftBGImg];
        tLeftShadow.frame =CGRectMake(tAsyImg.frame.origin.x-2, tAsyImg.frame.origin.y, 2, tHeight+TextH+tOffsetHeight);
        [_ContentScrollView addSubview:tLeftShadow];
        [tLeftShadow release];
        
        UIImageView* tRightShadow = [[UIImageView alloc] initWithImage:tRightBGImg];
        tRightShadow.frame =CGRectMake(tAsyImg.frame.origin.x+tAsyImg.frame.size.width,tAsyImg.frame.origin.y, 2, tHeight+TextH+tOffsetHeight);
        [_ContentScrollView addSubview:tRightShadow];
        [tRightShadow release];
        
        [_ViewsArr addObject:tAsyImg];
        
        UIView* tTextView = [[UIView alloc] initWithFrame:CGRectMake(0, tHeight, WidthMax, TextH+tOffsetHeight)];
        [tTextView setBackgroundColor:[UIColor whiteColor]];
        tTextView.userInteractionEnabled =YES;
        tTextView.tag = 10000+tBttTag;
        [tCustomBtt addSubview:tTextView];
        [tTextView release];
        
        if ([[tInDic objectForKey:@"description"] isEqualToString:@""]) {
            nil;
        } else {
            UILabel* tDesLabel =[[UILabel alloc] initWithFrame:CGRectMake(6, 6, 133, tOffsetHeight)];
            [tDesLabel setBackgroundColor:[UIColor clearColor]];
            [tDesLabel setFont:[UIFont systemFontOfSize:11.f]];
            tDesLabel.numberOfLines = 2;
            tDesLabel.text =[tInDic objectForKey:@"description"];
            [tTextView addSubview:tDesLabel];
            [tDesLabel release];

        }
        ////////////
        UIImageView* tImgView=[[UIImageView alloc] initWithImage:_CommentZC];
        tImgView.frame =CGRectMake(6, 10+tOffsetHeight, 10, 10);
        [tTextView addSubview:tImgView];
        [tImgView release];
        
        NSString* tForwardStr = [tInDic objectForKey:@"forward"];
        if (![[tInDic objectForKey:@"forward"] isKindOfClass:[NSString class]]) {
            tForwardStr = [NSString stringWithFormat:@"%d",[[tInDic objectForKey:@"forward"] intValue]];
        }
        UIFont* tBoldFont = [UIFont boldSystemFontOfSize:10];
        CGSize aSize = [tForwardStr sizeWithFont:tBoldFont];
        aSize.width +=6;
        UILabel* tForLab = [[UILabel alloc] initWithFrame:CGRectMake(18, 7+tOffsetHeight, aSize.width, 16)];
        tForLab.text =tForwardStr;
        [tForLab setFont:tBoldFont];
        [tForLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tForLab setBackgroundColor:[UIColor clearColor]];
        [tTextView addSubview:tForLab];
        tForLab.textAlignment = UITextAlignmentLeft;
        [tForLab release];
        
        int tIsLike =[[tInDic objectForKey:@"isliked"] intValue];//add by Scott
        int tComPosX = aSize.width+40;
        UIImageView* tFavImgView=[[UIImageView alloc] initWithImage:_CommentFav];
        if (tIsLike == 1) {
            [tFavImgView setImage:_CommentRedFav];
        }
        
        tFavImgView.frame =CGRectMake(aSize.width+20, 10+tOffsetHeight, 10, 10);
        tFavImgView.tag = 20000+tBttTag;
        [tTextView addSubview:tFavImgView];
        [tFavImgView release];
        
        NSString* tFavStr = [tInDic objectForKey:@"favorite"];
        if (![[tInDic objectForKey:@"favorite"] isKindOfClass:[NSString class]]) {
            tFavStr = [NSString stringWithFormat:@"%d",[[tInDic objectForKey:@"favorite"] intValue]];
        }
        CGSize aFSize = [tFavStr sizeWithFont:tBoldFont];
        aFSize.width +=6;
        UILabel* tFavLab = [[UILabel alloc] initWithFrame:CGRectMake(aSize.width+32, 7+tOffsetHeight, aFSize.width, 16)];
        tFavLab.tag = 30000+tBttTag;//add by Scott
        tFavLab.text =tFavStr;
        [tFavLab setFont:tBoldFont];
        [tFavLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tTextView addSubview:tFavLab];
        tFavLab.textAlignment = UITextAlignmentLeft;
        [tFavLab release];
        tComPosX+= (aFSize.width+8);
        
        
        UIImageView* tComImgView=[[UIImageView alloc] initWithImage:_CommentPL];
        tComImgView.frame =CGRectMake(tComPosX-14, 10+tOffsetHeight, 10, 10);
        [tTextView addSubview:tComImgView];
        [tComImgView release];
        
        NSString* tComStr = [tInDic objectForKey:@"comment"];
        if (![[tInDic objectForKey:@"comment"] isKindOfClass:[NSString class]]) {
            tComStr = [NSString stringWithFormat:@"%d",[[tInDic objectForKey:@"comment"] intValue]];
        }
        CGSize aCComSize = [tComStr sizeWithFont:tBoldFont];
        aCComSize.width +=1;
        UILabel* tComLab = [[UILabel alloc] initWithFrame:CGRectMake(tComPosX, 7+tOffsetHeight, aCComSize.width, 16)];
        tComLab.text =tComStr;
        [tComLab setFont:tBoldFont];
        [tComLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tTextView addSubview:tComLab];
        tComLab.textAlignment = UITextAlignmentLeft;
        [tComLab release];
        
        
        
        UIButton* tZhuanCaiBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tZhuanCaiBtt.frame =CGRectMake(0, tHeight+25+tOffsetHeight, 40, 15);
        tZhuanCaiBtt.tag =tBttTag;
        [tZhuanCaiBtt setTitle:@"转采" forState:UIControlStateNormal];
        [tZhuanCaiBtt setTitleColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1] forState:UIControlStateNormal];
        [tZhuanCaiBtt.titleLabel setFont:[UIFont boldSystemFontOfSize:11]];
        [tZhuanCaiBtt addTarget:self action:@selector(toZhuanCai:) forControlEvents:UIControlEventTouchUpInside];
        [tCustomBtt addSubview:tZhuanCaiBtt];
        
        UILabel* tDot = [[UILabel alloc] initWithFrame:CGRectMake(34, tHeight+25+tOffsetHeight, 5, 16)];
        tDot.text =@"•";
        [tDot setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tCustomBtt addSubview:tDot];
        [tDot release];
        
        UIButton* tLikeBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tLikeBtt.tag =tBttTag;
        if (tIsLike == 0) {
            tLikeBtt.frame =CGRectMake(36, tHeight+25+tOffsetHeight, 40, 15);
            [tLikeBtt setTitle:@"喜欢" forState:UIControlStateNormal];
        } else {
            tLikeBtt.frame =CGRectMake(36, tHeight+25+tOffsetHeight, 70, 15);
            [tLikeBtt setTitle:@"取消喜欢" forState:UIControlStateNormal];
        }
        
        [tLikeBtt setTitleColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1] forState:UIControlStateNormal];
        [tLikeBtt.titleLabel setFont:[UIFont boldSystemFontOfSize:11]];
        [tLikeBtt addTarget:self action:@selector(toDirectLike:) forControlEvents:UIControlEventTouchUpInside];
        [tCustomBtt addSubview:tLikeBtt];
        
//        UILabel* tWordLab =[[UILabel alloc] initWithFrame:CGRectMake(8, 54, WidthMax-16, 15)];
//        [tWordLab setFont:[UIFont boldSystemFontOfSize:13]];
//        [tWordLab setBackgroundColor:[UIColor clearColor]];
//        [tWordLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
//        [tWordLab setText:@"转采  喜欢"];
//        [tTextView addSubview:tWordLab];
//        [tWordLab release];
        
        CALayer* tLineLayer = [CALayer layer];
        tLineLayer.frame= CGRectMake(0, 47+tOffsetHeight, WidthMax, 1);
        [tLineLayer setBackgroundColor:[UIColor colorWithRed:218/255.f green:218/255.f blue:218/255.f alpha:1].CGColor];
        [tTextView.layer addSublayer:tLineLayer];
        
        
        AsyncImageView* tUseAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(4, tHeight+53+tOffsetHeight, 25, 25)];
        tUseAsyImg.m_BoolSetImage =YES;
        tUseAsyImg._imageRequestURL = [tInDic objectForKey:@"avatar"];
        tUseAsyImg._numStateRequested = need_Request;
        [tCustomBtt addSubview:tUseAsyImg];
        [tUseAsyImg customLoadImageFromURL];
        [tUseAsyImg release];
        
        UIButton* tUseImgView =[UIButton buttonWithType:UIButtonTypeCustom];
        //[tUseImgView setBackgroundImage:_UserIcon forState:UIControlStateNormal];
        [tUseImgView addTarget:self action:@selector(bttToShowUserInfo:) forControlEvents:UIControlEventTouchUpInside];
        tUseImgView.frame =CGRectMake(4, tHeight+53+tOffsetHeight, 25, 25);
        tUseImgView.tag =tBttTag;
        [tCustomBtt addSubview:tUseImgView];

        UILabel* tNameLab =[[UILabel alloc] initWithFrame:CGRectMake(36, 51+tOffsetHeight, WidthMax-40, 15)];
        [tNameLab setBackgroundColor:[UIColor clearColor]];
        [tNameLab setFont:[UIFont systemFontOfSize:8]];
        [tNameLab setTextColor:[UIColor  blackColor]];
        [tNameLab setText:[tInDic objectForKey:@"user_nickname"]];
        [tTextView addSubview:tNameLab];
        [tNameLab release];
        
        

        
        UILabel* tTitleLab =[[UILabel alloc] initWithFrame:CGRectMake(36, 63+tOffsetHeight, WidthMax-40, 15)];
        [tTitleLab setBackgroundColor:[UIColor clearColor]];
        [tTitleLab setFont:[UIFont systemFontOfSize:8]];
        [tTitleLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tTitleLab setText:[tInDic objectForKey:@"collect"]];
        [tTextView addSubview:tTitleLab];
        [tTitleLab release];
        
        UIButton* tCollectBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tCollectBtt.frame =CGRectMake(36, tHeight+63+tOffsetHeight, WidthMax-40, 15);
        tCollectBtt.tag =tBttTag;
        [tCollectBtt addTarget:self action:@selector(toShowCollect:) forControlEvents:UIControlEventTouchUpInside];
        [tCustomBtt addSubview:tCollectBtt];
        
        tBttTag++;
    }
    int tMaxScrollH =_LeftH;
    if (_RightH > tMaxScrollH) {
        tMaxScrollH =_RightH;
    }
    [_ContentScrollView setContentSize:CGSizeMake(320, tMaxScrollH)];
    [self scrollViewDidScroll:_ContentScrollView];
    if (Mode_Type_CollectList== m_NowModeType) {
        _ContentScrollView.frame =CGRectMake(0, 44, 320, 480-20-44-44);
    }
    
    [_PBLRequest setDelegate:nil];
    [_PBLRequest release];
    _PBLRequest= nil;
    [self hudWasHidden:nil];
    _IsRequesting =NO;
    [_BottomNot hide:YES];
    [self  doneLoadingTableViewData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
    _NowPageIndex--;
    [self hudWasHidden:nil];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
    

    [_PBLRequest setDelegate:nil];
    [_PBLRequest release];
    _PBLRequest= nil;
    _IsRequesting =NO;
    [_refreshHeaderView refreshLastUpdatedDate];
    [_BottomNot hide:YES];
    [self  doneLoadingTableViewData];
}


-(void) bttToDetail:(UIButton*)f_sender
{
    NSDictionary* toObject =nil;
    if (_SearchFuncationOpen) {
        toObject =[_SearchContentDicArr objectAtIndex:f_sender.tag];
    }else{
        toObject =[_ContentDicArr objectAtIndex:f_sender.tag];
    }
//    TZDetailViewController* tTZDetailVC = [[TZDetailViewController alloc] init];
//    if ([[toObject objectForKey:@"id"] isKindOfClass:[NSNumber class]]) {
//        tTZDetailVC.m_DetailID =[NSString stringWithFormat:@"%d",[[toObject objectForKey:@"id"] intValue]];
//    }else{
//        tTZDetailVC.m_DetailID =[toObject objectForKey:@"id"];
//    }
//    
//    tTZDetailVC.navigationItem.hidesBackButton =YES;
//    tTZDetailVC.hidesBottomBarWhenPushed =YES;
//    if (m_SuperNavVC != nil) {
//        [m_SuperNavVC pushViewController:tTZDetailVC animated:YES];
//    }else{
//        [self.navigationController pushViewController:tTZDetailVC animated:YES];
//    }
//    [tTZDetailVC release];
    TZScrollViewController* tTZDetailVC = [[TZScrollViewController alloc] init];
    if ([[toObject objectForKey:@"id"] isKindOfClass:[NSNumber class]]) {
        tTZDetailVC.m_DetailID =[NSString stringWithFormat:@"%d",[[toObject objectForKey:@"id"] intValue]];
    }else{
        tTZDetailVC.m_DetailID =[toObject objectForKey:@"id"];
    }
    
    tTZDetailVC.navigationItem.hidesBackButton =YES;
    tTZDetailVC.hidesBottomBarWhenPushed =YES;
    if (m_SuperNavVC != nil) {
        [m_SuperNavVC pushViewController:tTZDetailVC animated:YES];
    }else{
        [self.navigationController pushViewController:tTZDetailVC animated:YES];
    }
    [tTZDetailVC release];
}

-(void) bttToShowPBL:(UIButton*)f_sender
{
    NSDictionary* toObject =nil;
    NSString* tUserID =nil;
    if (_SearchFuncationOpen) {
        toObject =[_SearchContentDicArr objectAtIndex:f_sender.tag];
        if (Mode_Type_Attention == m_NowModeType) {
            MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
            tUserID = [tMainTabBar.m_UserDic objectForKey:@"user_id"];
        }
    }else{
        toObject =[_ContentDicArr objectAtIndex:f_sender.tag];
    }
    CollectListViewController* tNextVC = [[CollectListViewController alloc] init];
    tNextVC.navigationItem.hidesBackButton =YES;
    tNextVC.m_NowModeType=Mode_Type_CollectList;
    tNextVC.m_UserID =tUserID;
//    tNextVC.m_ShowUserID = [toObject objectForKey:@"user_id"];
    tNextVC.m_Collect_ID = [toObject objectForKey:@"id"];
    [self.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}


-(void) bttToShowUserInfo:(UIButton*)f_sender
{
    NSDictionary* toObject =nil;
    if (_SearchFuncationOpen) {
        toObject =[_SearchContentDicArr objectAtIndex:f_sender.tag];
    }else{
        toObject =[_ContentDicArr objectAtIndex:f_sender.tag];
    }
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    OwnViewController* tNextVC = [[OwnViewController alloc] initUesrID:[toObject objectForKey:@"user_id"]];
    tNextVC.navigationItem.hidesBackButton =YES;
    if (m_SuperNavVC != nil) {
        [m_SuperNavVC pushViewController:tNextVC animated:YES];
    }else{
        [self.navigationController pushViewController:tNextVC animated:YES];
    }
    
    [tNextVC release];
}

#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
	
	//  should be calling your tableviews data source model to reload
	//  put here just for demo
	_reloading = YES;
	
}

- (void)doneLoadingTableViewData{
	
	//  model should call this when its done loading
	_reloading = NO;
	[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_ContentScrollView];
	
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{	
    int tShowH =0;
    if ([scrollView isEqual:_ContentScrollView]) {
        [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
        tShowH = scrollView.contentOffset.y+scrollView.frame.size.height;
        for (int i =0; i<[_ViewsArr count];i++) {
            PBLAsyncImageView* tAsyImg = [_ViewsArr objectAtIndex:i];
            if (tAsyImg._numStateRequested == need_Request&& tAsyImg.frame.origin.y <= tShowH && (tAsyImg.frame.origin.y+tAsyImg.frame.size.height) >= tShowH-480 ) {
                tAsyImg._numStateRequested =haveSend_Request;
                [_BottomNot show:YES];
                [tAsyImg customLoadImageFromURL];
            }else if(tAsyImg._numStateRequested == suc_Request && tAsyImg.frame.origin.y <= tShowH && (tAsyImg.frame.origin.y+tAsyImg.frame.size.height) >= tShowH-480 ){
                [tAsyImg asyReadFileImg];
            }
        }
        
        if (tShowH > scrollView.contentSize.height+40 && !_IsRequesting) {
            [self requestPageData];
        }
    }else{
        tShowH = scrollView.contentOffset.y+scrollView.frame.size.height;
        for (int i =0; i<[_SearchViewsArr count];i++) {
            PBLAsyncImageView* tAsyImg = [_SearchViewsArr objectAtIndex:i];
            if (tAsyImg._numStateRequested == need_Request&& tAsyImg.frame.origin.y <= tShowH && (tAsyImg.frame.origin.y+tAsyImg.frame.size.height) >= tShowH-480 ) {
                tAsyImg._numStateRequested =haveSend_Request;
                [_BottomNot show:YES];
                [tAsyImg customLoadImageFromURL];
            }else if(tAsyImg._numStateRequested == suc_Request && tAsyImg.frame.origin.y <= tShowH && (tAsyImg.frame.origin.y+tAsyImg.frame.size.height) >= tShowH-480 ){
                [tAsyImg asyReadFileImg];
            }
        }
        if (tShowH > scrollView.contentSize.height+40 && !_IsRequesting) {
            if([_SearchTypeStr isEqualToString:@"blog"]){
                [self searchTieZiReuqest];
            }else if([_SearchTypeStr isEqualToString:@"collect"]){
                [self searchCollectReuqest];
            }else if([_SearchTypeStr isEqualToString:@"user"]){
                [self searchUserReuqest];
            }
        }
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
	
    if ([scrollView isEqual:_ContentScrollView]) {
        [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }

	
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
	
    if (_SearchContentSView == nil) {
        [self reloadTableViewDataSource];
        _NowPageIndex = 0;
        _BFPageIndex = _NowPageIndex;
        _NowPageIndex = 0;
        [_MaxID release];
        _MaxID =@"0";
        [_MaxID retain];
        _LeftH = 10;
        _RightH = 10;
        [self addHudLoad];
        [self clearAllBuffFile];
        
        [self requestPageData];
    }else{
        [self  doneLoadingTableViewData];
    }
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
	
	return _reloading; // should return if data source model is reloading
	
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
	
	return [NSDate date]; // should return date data source was last changed
	
}




#pragma mark -
#pragma mark searchchange Methods
-(void) initSearchView
{
    if (_SearchView != nil) {
        return;
    }
    _SearchTypeStr = @"blog";
    [_SearchTypeStr retain];
    _SearchView = [[UIView alloc] initWithFrame:CGRectMake(0, -88, 320, 88)];
    [_SearchView setBackgroundColor:[UIColor colorWithRed:236/255.f green:238/255.f blue:235/255.f alpha:1]];
    
    CALayer* tSearchLayer = [CALayer layer];
    tSearchLayer.borderWidth =1;
    tSearchLayer.borderColor = [UIColor colorWithRed:193/255.f green:193/255.f blue:193/255.f alpha:1].CGColor;
    [tSearchLayer setBackgroundColor:[UIColor whiteColor].CGColor];
    tSearchLayer.frame =CGRectMake(8, 12, 240, 30);
    [_SearchView.layer addSublayer:tSearchLayer];
    UITextField* tSearchField =[[UITextField alloc] initWithFrame:CGRectMake(12, 20, 235, 30)];
    tSearchField.placeholder =@"搜索关键字";
    tSearchField.delegate = self;
    tSearchField.tag =20;
    [tSearchField setFont:[UIFont systemFontOfSize:10]];
    [_SearchView addSubview:tSearchField];
    tSearchField.returnKeyType = UIReturnKeySearch;
    [tSearchField release];
    
    UIButton* tCancelBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    [tCancelBtt.titleLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"searchbttbg.png"]]];
    [tCancelBtt setTitleColor:[UIColor colorWithRed:94/255.f green:94/255.f blue:94/255.f alpha:1] forState:UIControlStateNormal];
    [tCancelBtt.titleLabel setFont:[UIFont systemFontOfSize:12]];
    tCancelBtt.layer.borderColor =[UIColor colorWithRed:193/255.f green:193/255.f blue:193/255.f alpha:1].CGColor;
    tCancelBtt.layer.borderWidth =1;
    tCancelBtt.layer.cornerRadius =4.f;
    [tCancelBtt addTarget:self action:@selector(AttDissSearch) forControlEvents:UIControlEventTouchUpInside];
    [tCancelBtt setTitle:@"取消" forState:UIControlStateNormal];
    tCancelBtt.frame =CGRectMake(256, 12, 58, 30);
    [_SearchView addSubview:tCancelBtt];
    
    
    //三部分
    UIButton* tTZbtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tTZbtt.frame =CGRectMake(0, 55, 106, 33);
    [tTZbtt setBackgroundColor:[UIColor colorWithRed:236/255.f  green:238/255.f blue:235/255.f alpha:1]];
    [tTZbtt setTitleColor:[UIColor colorWithRed:83/255.f green:83/255.f blue:83/255.f alpha:1] forState:UIControlStateNormal];
    [tTZbtt setTitle:@"帖子" forState:UIControlStateNormal];
    [tTZbtt.titleLabel setFont:[UIFont systemFontOfSize:12]];
    tTZbtt.tag =11;
    [tTZbtt addTarget:self action:@selector(changeSearchTJ:) forControlEvents:UIControlEventTouchUpInside];
    [_SearchView addSubview:tTZbtt];
    
    UIButton* tZJbtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tZJbtt.frame =CGRectMake(106, 55, 108, 33);
    [tZJbtt setBackgroundColor:[UIColor whiteColor]];
    [tZJbtt setTitleColor:[UIColor colorWithRed:83/255.f green:83/255.f blue:83/255.f alpha:1] forState:UIControlStateNormal];
    [tZJbtt setTitle:@"专辑" forState:UIControlStateNormal];
    [tZJbtt.titleLabel setFont:[UIFont systemFontOfSize:12]];
    tZJbtt.tag =12;
    [tZJbtt addTarget:self action:@selector(changeSearchTJ:) forControlEvents:UIControlEventTouchUpInside];
    
    CALayer* tLeftLine = [CALayer layer];
    tLeftLine.frame =CGRectMake(0, 0, 1, 33);
    [tLeftLine setBackgroundColor:[UIColor colorWithRed:201/255.f green:201/255.f blue:201/255.f alpha:1].CGColor];
    [tZJbtt.layer addSublayer:tLeftLine];
    CALayer* tRightLine = [CALayer layer];
    tRightLine.frame =CGRectMake(107, 0, 1, 33);
    [tRightLine setBackgroundColor:[UIColor colorWithRed:201/255.f green:201/255.f blue:201/255.f alpha:1].CGColor];
    [tZJbtt.layer addSublayer:tRightLine];
    [_SearchView addSubview:tZJbtt];
    
    UIButton* tREbtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tREbtt.frame =CGRectMake(214, 55, 106, 33);
    [tREbtt setBackgroundColor:[UIColor whiteColor]];
    [tREbtt setTitleColor:[UIColor colorWithRed:83/255.f green:83/255.f blue:83/255.f alpha:1] forState:UIControlStateNormal];
    [tREbtt setTitle:@"人儿" forState:UIControlStateNormal];
    [tREbtt.titleLabel setFont:[UIFont systemFontOfSize:12]];
    tREbtt.tag =13;
    [tREbtt addTarget:self action:@selector(changeSearchTJ:) forControlEvents:UIControlEventTouchUpInside];
    [_SearchView addSubview:tREbtt];
    
    
    UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
    tImgView.frame =CGRectMake(0, 54, 320, 5);
    [_SearchView addSubview:tImgView];
    [tImgView release];
    [self.view addSubview:_SearchView];
    
}

-(void) registInput:(UIButton*)f_sender
{
    [f_sender removeFromSuperview];
    UITextField* tSearchField =(UITextField*)[_SearchView viewWithTag:20];
    [tSearchField resignFirstResponder];
}

-(void) showSearchView
{
    _SearchView.frame = CGRectMake(0, -88, 320, 88);
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDelay:0.2];
    _SearchView.frame =CGRectMake(0, 0, 320, 88);
    _ContentScrollView.frame =CGRectMake(0, 88, 320, 480-20-44-49-88);
    [UIView commitAnimations];
}

-(void) dissSearchView
{
    if (_SearchFuncationOpen) {
        _SearchFuncationOpen =NO;
        [_SearchContentSView removeFromSuperview];
        [_SearchContentSView release];
        _SearchContentSView =nil;
        UIButton* tBtt0 =(UIButton*)[_SearchView viewWithTag:11];
        UIButton* tBtt1 =(UIButton*)[_SearchView viewWithTag:12];
        UIButton* tBtt2 =(UIButton*)[_SearchView viewWithTag:13];
        [tBtt0 setTitle:[NSString stringWithFormat:@"帖子"]forState:UIControlStateNormal];
        [tBtt1 setTitle:[NSString stringWithFormat:@"专辑"] forState:UIControlStateNormal];
        [tBtt2 setTitle:[NSString stringWithFormat:@"人儿"] forState:UIControlStateNormal];
        MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
        tMainTabBar.m_TabbarCustom.hidden =NO;
        //清理搜索缓存
        NSString* tTemp = NSTemporaryDirectory();
        NSString *fileName=[tTemp stringByAppendingPathComponent:_SearchTempFName];
        NSFileManager* tFileManager = [NSFileManager defaultManager];
        NSError* tError = nil;
        if ([tFileManager fileExistsAtPath:fileName]) {
            [tFileManager removeItemAtPath:fileName error:&tError];
            NSLog(@"%@",[tError description]);
        }
    }
    [[self.view viewWithTag:1001] removeFromSuperview];
    UITextField* tSearchField =(UITextField*)[_SearchView viewWithTag:20];
    [tSearchField resignFirstResponder];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDelay:0.2];
    _SearchView.frame =CGRectMake(0, -88, 320, 88);
    _ContentScrollView.frame =CGRectMake(0, 0, 320, 480-20-44-49);
    [UIView commitAnimations];
}

-(void)changeSearchTJ:(UIButton*)f_sender
{
    int tType =[f_sender tag]-11;
    UIButton* tBtt0 =(UIButton*)[_SearchView viewWithTag:11];
    UIButton* tBtt1 =(UIButton*)[_SearchView viewWithTag:12];
    UIButton* tBtt2 =(UIButton*)[_SearchView viewWithTag:13];
    [tBtt0 setBackgroundColor:[UIColor whiteColor]];
    [tBtt1 setBackgroundColor:[UIColor whiteColor]];
    [tBtt2 setBackgroundColor:[UIColor whiteColor]];
    [f_sender setBackgroundColor:[UIColor colorWithRed:236/255.f  green:238/255.f blue:235/255.f alpha:1]];
    
    [_SearchTypeStr release];
    _SearchTypeStr = nil;
    if (tType ==0) {
        _SearchTypeStr = @"blog";
    }else if(tType == 1){
        _SearchTypeStr = @"collect";
    }else if(tType == 2){
        _SearchTypeStr = @"user";
    }
    [_SearchTypeStr retain];
    
    if (_SearchFuncationOpen) {
        [self  showSearchContentView];
    }
}

#pragma mark -
#pragma mark MBProgressHUDDelegate
- (void)hudWasHidden:(MBProgressHUD *)hud{
    /*p_MBHUD.delegate = nil;
	[p_MBHUD removeFromSuperview];
	[p_MBHUD release];
	p_MBHUD=nil;*/
}

-(void) addHudLoad{
	/*if (p_MBHUD == nil) {
        if (m_NowModeType == Mode_Type_InfoShow || Mode_Type_ShortInfoShow== m_NowModeType) {
            p_MBHUD = [[MBProgressHUD alloc] initWithView:m_SuperNavVC.view];
        }else{
            p_MBHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
        }
		
		// Add HUD to screen
		[self.navigationController.view addSubview:p_MBHUD];
		// Regisete for HUD callbacks so we can remove it from the window at the right time
		p_MBHUD.delegate = self;
		p_MBHUD.labelText = @"请求数据中...";
		[p_MBHUD show:YES];
	}*/
}

#pragma mark -
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    UIButton* tRegistBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tRegistBtt.frame =CGRectMake(0, 90, 320, 300);
    tRegistBtt.alpha =0.7;
    tRegistBtt.tag =1001;
    [tRegistBtt addTarget:self action:@selector(registInput:) forControlEvents:UIControlEventTouchUpInside];
    [tRegistBtt setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:tRegistBtt];
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if ([textField.text length] > 0) {
        [[self.view viewWithTag:1001] removeFromSuperview];
        [textField resignFirstResponder];
        
        [self addHudLoad];
        [_SearchKeyWord release];
        _SearchKeyWord =nil;
        _SearchKeyWord= textField.text;
        [_SearchKeyWord retain];
        NSString* tRequestStr =[NSString stringWithFormat:@"%@?app=blog&act=search&keyword=%@",RequestMainURL,textField.text];
        tRequestStr = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tRequestStr, nil, nil, kCFStringEncodingUTF8);
        NSURL* tRequestURL =[NSURL URLWithString:tRequestStr];
        
        ASIHTTPRequest* tRequestSearchNum = [ASIHTTPRequest requestWithURL:tRequestURL];
        [tRequestSearchNum setDelegate:self];
        [tRequestSearchNum setDidFailSelector:@selector(requestSearchFail:)];
        [tRequestSearchNum setDidFinishSelector:@selector(requestSearchNum:)];
        [tRequestSearchNum startAsynchronous];
    }
    return YES;
}


#pragma mark -
#pragma mark 搜索结果显示部分
-(void) requestSearchFail:(ASIHTTPRequest*)request
{
    [self hudWasHidden:nil];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}
-(void) requestSearchNum:(ASIHTTPRequest*)request
{
    NSError* tError;
    
    NSString* tReqStr = [request responseString];
    NSLog(@"ads json data =%@",tReqStr);

    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
	NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [_PBLRequest setDelegate:nil];
        [_PBLRequest release];
        _PBLRequest= nil;
        [_BottomNot hide:YES];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [_PBLRequest setDelegate:nil];
        [_PBLRequest release];
        _PBLRequest= nil;
        [_BottomNot hide:YES];
        return;
    }
    
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    _SearchFuncationOpen = YES;
    [_TieZiSearchDic release];//贴子的结果
    [_CollectSearchDic release];//专辑
    [_RenErSearchDic  release];//人儿
    _TieZiSearchDic =nil;
    _CollectSearchDic =nil;
    _RenErSearchDic =nil;
    
    //搜索贴子缓存区创建
    NSString* tTemp = NSTemporaryDirectory();
    [_SearchTempFName release];
    _SearchTempFName =nil;
    _SearchTempFName =[NSString stringWithFormat:@"pbltemp%d",-1];
    [_SearchTempFName retain];
    _SearchFloderIndex = -1;
    NSString *fileName=[tTemp stringByAppendingPathComponent:_SearchTempFName];
    NSFileManager* tFileManager = [NSFileManager defaultManager];
    if ([tFileManager fileExistsAtPath:fileName]) {
        [tFileManager removeItemAtPath:fileName error:&tError];
    }
    [tFileManager createDirectoryAtPath:fileName withIntermediateDirectories:NO attributes:nil error:&tError];
    
    NSDictionary* tDataDic = [tDictionary objectForKey:@"data"];

    UIButton* tBtt0 =(UIButton*)[_SearchView viewWithTag:11];
    UIButton* tBtt1 =(UIButton*)[_SearchView viewWithTag:12];
    UIButton* tBtt2 =(UIButton*)[_SearchView viewWithTag:13];
    _BolgNum =[[tDataDic objectForKey:@"blog_count"]intValue];
    _CollectNum =[[tDataDic objectForKey:@"collect_count"]intValue];
    _UserNum =[[tDataDic objectForKey:@"user_count"]intValue];
    [tBtt0 setTitle:[NSString stringWithFormat:@"%d   帖子",_BolgNum]forState:UIControlStateNormal];
    [tBtt1 setTitle:[NSString stringWithFormat:@"%d   专辑",_CollectNum] forState:UIControlStateNormal];
    [tBtt2 setTitle:[NSString stringWithFormat:@"%d   人儿",_UserNum] forState:UIControlStateNormal];
    
    [self  showSearchContentView];
}

//直接转采
-(void) toZhuanCai:(UIButton*)f_sender
{
    NSDictionary* tDic =nil;
    if (_SearchFuncationOpen) {
        tDic =[_SearchContentDicArr objectAtIndex:f_sender.tag];
    }else{
        tDic =[_ContentDicArr objectAtIndex:f_sender.tag];
    }
    NSLog(@"%@",[tDic description]);
    
    //modify by Scott
    MainTabBarController* tMainTabBar = nil;
    if (m_SuperNavVC != nil) {
        tMainTabBar =(MainTabBarController*)m_SuperNavVC.tabBarController;
    }else{
        tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
    }
    if (tMainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return;
    }
    
    AddAlbumViewController* tShowAdd =[[AddAlbumViewController alloc] initType:FORWARD_BLOG];
    id tObjectView =[_ViewsArr objectAtIndex:f_sender.tag];
    
    UIImage* tImg = nil;
    if ([tObjectView isKindOfClass:[PBLAsyncImageView class]]) {
        tImg = [((AsyncImageView*)tObjectView) GetUIImage];
    }
    tShowAdd.headimage =tImg;
    NSLog(@"%@",[tDic objectForKey:@"user_id"]);
    tShowAdd.user_id = [tMainTabBar.m_UserDic objectForKey:@"user_id"];
    tShowAdd.titletext= [tDic objectForKey:@"description"];
//    tShowAdd.Albumname= [tDic objectForKey:@"collect"];
    tShowAdd.blogid= [tDic objectForKey:@"id"];
    tShowAdd.navigationItem.hidesBackButton =YES;
    tMainTabBar.m_TabbarCustom.hidden = YES;
    if (m_SuperNavVC != nil) {
        [m_SuperNavVC pushViewController:tShowAdd animated:YES];
    }else{
        [self.navigationController pushViewController:tShowAdd animated:YES];
    }
    
    [tShowAdd release];
}

-(void) toShowCollect:(UIButton*)f_sender
{
    NSDictionary* tDic =nil;
    if (_SearchFuncationOpen) {
        tDic =[_SearchContentDicArr objectAtIndex:f_sender.tag];
    }else{
        tDic =[_ContentDicArr objectAtIndex:f_sender.tag];
    }
    NSLog(@"%@",[tDic description]);
    
//    AlbumModel* tAlbDic= [m_albumdata objectAtIndex:_tag];
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    CollectListViewController* tNextVC = [[CollectListViewController alloc] init];
    tNextVC.navigationItem.hidesBackButton =YES;
    tNextVC.m_NowModeType=Mode_Type_CollectList;
    tNextVC.m_UserID =[tDic objectForKey:@"user_id"];
    //    tNextVC.m_ShowUserID = [NSString stringWithFormat:@"%d",tAlbDic.userid];
    tNextVC.m_Collect_ID = [tDic objectForKey:@"collect_id"];
    //tNextVC.type = m_type;
    [self.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}

-(void) toDirectLike:(UIButton*)f_sender
{
    NSDictionary* tDic =nil;
    if (_SearchFuncationOpen) {
        tDic =[_SearchContentDicArr objectAtIndex:f_sender.tag];
    }else{
        tDic =[_ContentDicArr objectAtIndex:f_sender.tag];
    }
    NSLog(@"%@",[tDic description]);
   
    //modify by Scott
    MainTabBarController* tMainTabBar = nil;
    if (m_SuperNavVC != nil) {
         tMainTabBar =(MainTabBarController*)m_SuperNavVC.tabBarController;
    }else{
         tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
    }
    
    if (tMainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return;
    }
    NSString* tRequestURL = nil;
    if ([f_sender.titleLabel.text isEqualToString:@"喜欢"]) {
        tRequestURL =[NSString stringWithFormat:@"%@?app=blog&act=like&user_id=%@&blog_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[tDic objectForKey:@"id"]];
    }else{
        tRequestURL =[NSString stringWithFormat:@"%@?app=blog&act=unlike&user_id=%@&blog_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[tDic objectForKey:@"id"]];
    }

    
    UIView* tTextView =[[f_sender superview] viewWithTag:10000+f_sender.tag];
    UIImageView* tImgView = (UIImageView*)[tTextView viewWithTag:20000+f_sender.tag];
    UILabel* tNum = (UILabel*)[[f_sender superview] viewWithTag:30000+f_sender.tag];//add by Scott
    ASIHTTPRequest* tLikeRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:tRequestURL]];
    tLikeRequest.m_Tag = (int)tImgView;
    tLikeRequest.m_Object = (int)f_sender;
    tLikeRequest.m_Num = (int)tNum;//add by Scott
    [tLikeRequest setDelegate:self];
    [tLikeRequest setDidFailSelector:@selector(dolikeRequestFail:)];
    [tLikeRequest setDidFinishSelector:@selector(dolikeRequestFinish:)];
    [tLikeRequest startAsynchronous];
    [self addHudLoad];
}

-(void)dolikeRequestFail:(ASIHTTPRequest*)request
{
    [self hudWasHidden:nil];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}
-(void)dolikeRequestFinish:(ASIHTTPRequest*)request
{
    NSError* tError;
    NSString* tReqStr =[request responseString];
    NSLog(@"ads json data =%@",[request responseString]);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:NO delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    UIButton* tBtt =(UIButton*)request.m_Object;
    UIImageView* tImgView =(UIImageView*)request.m_Tag;
    UILabel* tNum=(UILabel*)request.m_Num;//add by Scott
    if ([tBtt.titleLabel.text isEqualToString:@"喜欢"]) {
        [tAppDel showWithCustomView:@"喜欢成功" detailText:@"" isCue:NO delayTime:2.0f];
        [tBtt setTitle:@"取消喜欢" forState:UIControlStateNormal];
        CGRect aframe =  tBtt.frame;
        aframe.size.width =70;
        tBtt.frame = aframe;
        [tImgView setImage:_CommentRedFav];
        //tNum.text = @"+";//add by Scott
        tNum.text = [NSString stringWithFormat:@"%d",tNum.text.intValue+1];
    }else{
        [tAppDel showWithCustomView:@"取消喜欢成功" detailText:@"" isCue:NO delayTime:2.0f];
        [tBtt setTitle:@"喜欢" forState:UIControlStateNormal];
        CGRect aframe =  tBtt.frame;
        aframe.size.width =40;
        tBtt.frame = aframe;
        [tImgView setImage:_CommentFav];
        tNum.text = [NSString stringWithFormat:@"%d",tNum.text.intValue-1];
    }
    [self hudWasHidden:nil];
}

//搜索内容处理和数据请求
-(void) showSearchContentView
{
    [_SearchContentSView removeFromSuperview];
    [_SearchContentSView release];
    _SearchContentSView = nil;
    _SearchContentSView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 90, 320, 480-20-44-90)];
    [_SearchContentSView setBackgroundColor:[UIColor colorWithRed:193/255.f green:193/255.f blue:193/255.f alpha:1]];
    _SearchContentSView.delegate = self;
    [self.view addSubview:_SearchContentSView];
    self.view.frame =CGRectMake(0, 0, 320, 480-20-44);
    
    if ([_SearchTypeStr isEqualToString:@"blog"]) {
        if (_BolgNum == 0) {
            UILabel* tTipLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 142, 320, 20)];
            [tTipLab setBackgroundColor:[UIColor clearColor]];
            [tTipLab setText:@"未搜索到任何结果"];
            tTipLab.textAlignment =UITextAlignmentCenter;
            tTipLab.shadowColor = [UIColor grayColor];
            [tTipLab setTextColor:[UIColor colorWithRed:73/255.f green:73/255.f blue:73/255.f alpha:1]];
            [_SearchContentSView addSubview:tTipLab];
            [tTipLab release];
            [self hudWasHidden:nil];
        }else{
            //清理搜索缓存
            NSString* tTemp = NSTemporaryDirectory();
            NSString *fileName=[tTemp stringByAppendingPathComponent:_SearchTempFName];
            NSFileManager* tFileManager = [NSFileManager defaultManager];
            NSError* tError = nil;
            if ([tFileManager fileExistsAtPath:fileName]) {
                NSArray* tArr = [tFileManager contentsOfDirectoryAtPath:fileName error:&tError];
                NSString *filename;
                NSEnumerator *eEnum = [tArr objectEnumerator];
                while ((filename = [eEnum nextObject])) {
                    [tFileManager removeItemAtPath:[_SearchTempFName stringByAppendingPathComponent:filename] error:NULL];
                }
                NSLog(@"%@",[tError description]);
            }
            _SearchPageIndex = 0;
            _SearchLeftH =10;
            _SearchRightH =10;
            [_SearchContentDicArr removeAllObjects];//数据
            [_SearchViewsArr removeAllObjects];
            if (_TieZiSearchDic != nil) {
                [self searchResTieZiViewShow:_TieZiSearchDic];
                [self hudWasHidden:nil];
            }else{
                if (p_MBHUD == nil) {
                    [self addHudLoad];
                }
                [self searchTieZiReuqest];
            }
        }
    }else if([_SearchTypeStr isEqualToString:@"collect"]){
        if (_BolgNum == 0) {
            UILabel* tTipLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 152, 320, 20)];
            [tTipLab setBackgroundColor:[UIColor clearColor]];
            [tTipLab setText:@"未搜索到任何结果"];
            tTipLab.textAlignment =UITextAlignmentCenter;
            tTipLab.shadowColor = [UIColor grayColor];
            [tTipLab setTextColor:[UIColor colorWithRed:73/255.f green:73/255.f blue:73/255.f alpha:1]];
            [_SearchContentSView addSubview:tTipLab];
            [tTipLab release];
            [self hudWasHidden:nil];
        }else{
            NSString* tTemp = NSTemporaryDirectory();
            NSString *fileName=[tTemp stringByAppendingPathComponent:_SearchTempFName];
            NSFileManager* tFileManager = [NSFileManager defaultManager];
            NSError* tError = nil;
            if ([tFileManager fileExistsAtPath:fileName]) {
                NSArray* tArr = [tFileManager contentsOfDirectoryAtPath:fileName error:&tError];
                NSString *filename;
                NSEnumerator *eEnum = [tArr objectEnumerator];
                while ((filename = [eEnum nextObject])) {
                    [tFileManager removeItemAtPath:[_SearchTempFName stringByAppendingPathComponent:filename] error:NULL];
                }
                NSLog(@"%@",[tError description]);
            }
            _SearchPageIndex = 0;
            _SearchLeftH =10;
            [_SearchContentDicArr removeAllObjects];
            [_SearchViewsArr removeAllObjects];
            if (_CollectSearchDic != nil) {
                [self searchResCollectViewShow:_CollectSearchDic];
                [self hudWasHidden:nil];
            }else{
                if (p_MBHUD == nil) {
                    [self addHudLoad];
                }
                [self searchCollectReuqest];
            }
        }
    }else if([_SearchTypeStr isEqualToString:@"user"]){
        if (_BolgNum == 0) {
            UILabel* tTipLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 152, 320, 20)];
            [tTipLab setBackgroundColor:[UIColor clearColor]];
            [tTipLab setText:@"未搜索到任何结果"];
            tTipLab.textAlignment =UITextAlignmentCenter;
            tTipLab.shadowColor = [UIColor grayColor];
            [tTipLab setTextColor:[UIColor colorWithRed:73/255.f green:73/255.f blue:73/255.f alpha:1]];
            [_SearchContentSView addSubview:tTipLab];
            [tTipLab release];
            [self hudWasHidden:nil];
        }else{
            NSString* tTemp = NSTemporaryDirectory();
            NSString *fileName=[tTemp stringByAppendingPathComponent:_SearchTempFName];
            NSFileManager* tFileManager = [NSFileManager defaultManager];
            NSError* tError = nil;
            if ([tFileManager fileExistsAtPath:fileName]) {
                NSArray* tArr = [tFileManager contentsOfDirectoryAtPath:fileName error:&tError];
                NSString *filename;
                NSEnumerator *eEnum = [tArr objectEnumerator];
                while ((filename = [eEnum nextObject])) {
                    [tFileManager removeItemAtPath:[_SearchTempFName stringByAppendingPathComponent:filename] error:NULL];
                }
                NSLog(@"%@",[tError description]);
            }
            _SearchPageIndex = 0;
            _SearchLeftH =0;
            [_SearchContentDicArr removeAllObjects];
            [_SearchViewsArr removeAllObjects];
            if (_RenErSearchDic != nil) {
                [self searchResUserViewShow:_RenErSearchDic];
                [self hudWasHidden:nil];
            }else{
                if (p_MBHUD == nil) {
                    [self addHudLoad];
                }
                [self searchUserReuqest];
            }
        }
    }
}

//贴子搜索的
-(void) searchTieZiReuqest
{
    if (!_IsSearchRequesting) {
        _IsSearchRequesting =YES;
        NSString* tRequestStr = [NSString stringWithFormat:@"%@?app=blog&act=searchDetail&keyword=%@&type=%@&start=%d&limit=%d",RequestMainURL,_SearchKeyWord,_SearchTypeStr,_SearchPageIndex,PageSize];
        tRequestStr = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tRequestStr, nil, nil, kCFStringEncodingUTF8);
        NSURL* tRequestURL =[NSURL URLWithString:tRequestStr];
        
        ASIHTTPRequest* tRequestSearchNum = [ASIHTTPRequest requestWithURL:tRequestURL];
        [tRequestSearchNum setDelegate:self];
        [tRequestSearchNum setDidFailSelector:@selector(requestSResFail:)];
        [tRequestSearchNum setDidFinishSelector:@selector(requestSResFinish:)];
        [tRequestSearchNum startAsynchronous];
        _SearchPageIndex++;
    }
}

//专辑搜索的
-(void) searchCollectReuqest
{
    if (!_IsSearchRequesting) {
        _IsSearchRequesting =YES;
        NSString* tRequestStr = [NSString stringWithFormat:@"%@?app=blog&act=searchDetail&keyword=%@&type=%@&start=%d&limit=%d",RequestMainURL,_SearchKeyWord,_SearchTypeStr,_SearchPageIndex,PageSize];
        tRequestStr = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tRequestStr, nil, nil, kCFStringEncodingUTF8);
        NSURL* tRequestURL =[NSURL URLWithString:tRequestStr];
        
        ASIHTTPRequest* tRequestSearchNum = [ASIHTTPRequest requestWithURL:tRequestURL];
        [tRequestSearchNum setDelegate:self];
        [tRequestSearchNum setDidFailSelector:@selector(requestCollectFail:)];
        [tRequestSearchNum setDidFinishSelector:@selector(requestCollectFinish:)];
        [tRequestSearchNum startAsynchronous];
        _SearchPageIndex++;
    }
}

//人儿搜索的
-(void) searchUserReuqest
{
    NSString* tRequestStr = [NSString stringWithFormat:@"%@?app=blog&act=searchDetail&keyword=%@&type=%@&start=%d&limit=%d",RequestMainURL,_SearchKeyWord,_SearchTypeStr,_SearchPageIndex,PageSize];
    tRequestStr = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tRequestStr, nil, nil, kCFStringEncodingUTF8);
    NSURL* tRequestURL =[NSURL URLWithString:tRequestStr];
    
    ASIHTTPRequest* tRequestSearchNum = [ASIHTTPRequest requestWithURL:tRequestURL];
    [tRequestSearchNum setDelegate:self];
    [tRequestSearchNum setDidFailSelector:@selector(requestUserFail:)];
    [tRequestSearchNum setDidFinishSelector:@selector(requestUserFinish:)];
    [tRequestSearchNum startAsynchronous];
}
-(void)requestUserFinish:(ASIHTTPRequest*)request
{
    NSError* tError;
    NSString* tReqStr = [request responseString];
    NSLog(@"ads json data =%@",tReqStr);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
	NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    [_RenErSearchDic release];
    _RenErSearchDic =nil;
    _RenErSearchDic = [tDictionary objectForKey:@"data"];
    [_RenErSearchDic retain];
    
    [self searchResUserViewShow:_RenErSearchDic];
    [self hudWasHidden:nil];
}
-(void)requestCollectFinish:(ASIHTTPRequest*)request
{
    NSError* tError;
    NSString* tReqStr = [request responseString];
    NSLog(@"ads json data =%@",tReqStr);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
	NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [_PBLRequest setDelegate:nil];
        [_PBLRequest release];
        _PBLRequest= nil;
        [_BottomNot hide:YES];
        return;
    }
    [_CollectSearchDic release];
    _CollectSearchDic =nil;
    _CollectSearchDic = [tDictionary objectForKey:@"data"];
    [_CollectSearchDic retain];
    
    [self searchResCollectViewShow:_CollectSearchDic];
    [self hudWasHidden:nil];
    _IsSearchRequesting =NO;
}

-(void)requestSResFinish:(ASIHTTPRequest*)request
{
    NSError* tError;
    NSString* tReqStr = [request responseString];
    NSLog(@"ads json data =%@",tReqStr);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
	NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        _IsSearchRequesting =NO;
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        _IsSearchRequesting =NO;
        return;
    }
    [_TieZiSearchDic release];
    _TieZiSearchDic =nil;
    _TieZiSearchDic = [tDictionary objectForKey:@"data"];
    [_TieZiSearchDic retain];

    [self searchResTieZiViewShow:_TieZiSearchDic];
    _IsSearchRequesting =NO;
    [self hudWasHidden:nil];
}

-(void)requestSResFail:(ASIHTTPRequest*)request
{
    _SearchPageIndex--;
    [self hudWasHidden:nil];
    _IsSearchRequesting =NO;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}

-(void)requestCollectFail:(ASIHTTPRequest*)request
{
    _SearchPageIndex--;
    [self hudWasHidden:nil];
    _IsSearchRequesting =NO;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}
-(void)requestUserFail:(ASIHTTPRequest*)request
{
    [self hudWasHidden:nil];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}

//搜索结果 贴子 显示
-(void) searchResTieZiViewShow:(NSArray*)tDicArr
{
    int tBttTag = [_SearchContentDicArr count];
    [_SearchContentDicArr addObjectsFromArray:tDicArr];
    
    
    int tWidth = 0;
    int tHeight = 0;
    float tScaleIndex = 0.f;
    UIImage* tLeftBGImg = [UIImage imageNamed:@"block_shadow_left.png"];
    UIImage* tRightBGImg = [UIImage imageNamed:@"block_shadow_right.png"];
    UIImage* tTopBGImg = [UIImage imageNamed:@"block_shadow_top.png"];
    UIImage* tBottomBGImg = [UIImage imageNamed:@"block_shadow_bottom.png"];
    for (NSDictionary* tInDic in tDicArr) {
        UIButton* tCustomBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tCustomBtt.tag = tBttTag;
        [tCustomBtt addTarget:self action:@selector(bttToDetail:) forControlEvents:UIControlEventTouchUpInside];
        
        tWidth = [[tInDic objectForKey:@"image_width"] intValue];
        tHeight = [[tInDic objectForKey:@"image_height"] intValue];
        tScaleIndex = WidthMax/tWidth;
        tHeight = tHeight*tScaleIndex;
        
        int tOffsetHeight = 0;//add by Scott
        if ([[tInDic objectForKey:@"description"] isEqualToString:@""]) {
            tOffsetHeight = 0;
        } else {
            if ([[tInDic objectForKey:@"description"] length] > 11) {
                tOffsetHeight = 30;
            } else {
                tOffsetHeight = 18;
            }
        }
        
        int tCheckPos = 0;
        int tCheckValue = _SearchLeftH;
        if (tCheckValue > _SearchRightH) {
            tCheckPos =2;
        }
        PBLAsyncImageView* tAsyImg = nil;
        switch (tCheckPos) {
            case 0://左
            {
                tAsyImg = [[PBLAsyncImageView alloc] initWithFrame:CGRectMake(10, _SearchLeftH, WidthMax, tHeight)];
                tCustomBtt.frame =CGRectMake(10, _SearchLeftH, WidthMax, tHeight+TextH+tOffsetHeight);
                _SearchLeftH+=tHeight+LineDis+TextH+tOffsetHeight;
            }
                break;
            case 2://右
            {
                tAsyImg = [[PBLAsyncImageView alloc] initWithFrame:CGRectMake(165, _SearchRightH, WidthMax, tHeight)];
                tCustomBtt.frame =CGRectMake(165, _SearchRightH, WidthMax, tHeight+TextH+tOffsetHeight);
                _SearchRightH+=tHeight+LineDis+TextH+tOffsetHeight;
            }
                break;
        }
        [tAsyImg setBackgroundColor:[UIColor colorWithRed:183/255.f green:185/255.f blue:183/255.f alpha:1.0]];
        
        NSString* tImgURL =[tInDic objectForKey:@"image"];
        tAsyImg._imageRequestURL =tImgURL;
        tAsyImg._numStateRequested =need_Request;
        tAsyImg.m_BoolSetImage =YES;
        tAsyImg.m_FloderIndex = -1;
        tAsyImg.m_AsyTag = tBttTag;
        
        [_SearchContentSView addSubview:tAsyImg];
        [_SearchContentSView addSubview:tCustomBtt];
        [tAsyImg release];
        
        [_SearchViewsArr addObject:tAsyImg];
        UIImageView* tTopShadow = [[UIImageView alloc] initWithImage:tTopBGImg];
        tTopShadow.frame =CGRectMake(tAsyImg.frame.origin.x, tAsyImg.frame.origin.y-2, tAsyImg.frame.size.width, 2);
        [_SearchContentSView addSubview:tTopShadow];
        [tTopShadow release];
        
        UIImageView* tBottomShadow = [[UIImageView alloc] initWithImage:tBottomBGImg];
        tBottomShadow.frame =CGRectMake(tAsyImg.frame.origin.x, tAsyImg.frame.origin.y+tHeight+TextH+tOffsetHeight, tAsyImg.frame.size.width, 2);
        [_SearchContentSView addSubview:tBottomShadow];
        [tBottomShadow release];
        
        UIImageView* tLeftShadow = [[UIImageView alloc] initWithImage:tLeftBGImg];
        tLeftShadow.frame =CGRectMake(tAsyImg.frame.origin.x-2, tAsyImg.frame.origin.y, 2, tHeight+TextH+tOffsetHeight);
        [_SearchContentSView addSubview:tLeftShadow];
        [tLeftShadow release];
        
        UIImageView* tRightShadow = [[UIImageView alloc] initWithImage:tRightBGImg];
        tRightShadow.frame =CGRectMake(tAsyImg.frame.origin.x+tAsyImg.frame.size.width,tAsyImg.frame.origin.y, 2, tHeight+TextH+tOffsetHeight);
        [_SearchContentSView addSubview:tRightShadow];
        [tRightShadow release];
        
        UIView* tTextView = [[UIView alloc] initWithFrame:CGRectMake(0, tHeight, WidthMax, TextH+tOffsetHeight)];
        [tTextView setBackgroundColor:[UIColor whiteColor]];
        tTextView.userInteractionEnabled =YES;
        tTextView.tag = 10000+tBttTag;
        [tCustomBtt addSubview:tTextView];
        [tTextView release];
        
        if ([[tInDic objectForKey:@"description"] isEqualToString:@""]) {
            nil;
        } else {
            UILabel* tDesLabel =[[UILabel alloc] initWithFrame:CGRectMake(6, 6, 133, tOffsetHeight)];
            [tDesLabel setBackgroundColor:[UIColor clearColor]];
            [tDesLabel setFont:[UIFont systemFontOfSize:11.f]];
            tDesLabel.numberOfLines = 2;
            tDesLabel.text =[tInDic objectForKey:@"description"];
            [tTextView addSubview:tDesLabel];
            [tDesLabel release];
        }

        
        UIImageView* tImgView=[[UIImageView alloc] initWithImage:_CommentZC];
        tImgView.frame =CGRectMake(6, 10+tOffsetHeight, 10, 10);
        [tTextView addSubview:tImgView];
        [tImgView release];
        
        NSString* tForwardStr = [tInDic objectForKey:@"forward"];
        if (![[tInDic objectForKey:@"forward"] isKindOfClass:[NSString class]]) {
            tForwardStr = [NSString stringWithFormat:@"%d",[[tInDic objectForKey:@"forward"] intValue]];
        }
        UIFont* tBoldFont = [UIFont boldSystemFontOfSize:10];
        CGSize aSize = [tForwardStr sizeWithFont:tBoldFont];
        aSize.width +=6;
        UILabel* tForLab = [[UILabel alloc] initWithFrame:CGRectMake(18, 7+tOffsetHeight, aSize.width, 16)];
        tForLab.text =tForwardStr;
        [tForLab setFont:tBoldFont];
        [tForLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tForLab setBackgroundColor:[UIColor clearColor]];
        [tTextView addSubview:tForLab];
        tForLab.textAlignment = UITextAlignmentLeft;
        [tForLab release];
        
        int tIsLike =[[tInDic objectForKey:@"isliked"] intValue];//add by Scott
        int tComPosX = aSize.width+40;
        UIImageView* tFavImgView=[[UIImageView alloc] initWithImage:_CommentFav];
        if (tIsLike == 1) {
            [tFavImgView setImage:_CommentRedFav];
        }
        tFavImgView.frame =CGRectMake(aSize.width+20, 10+tOffsetHeight, 10, 10);
        tFavImgView.tag =20000+tBttTag;
        [tTextView addSubview:tFavImgView];
        [tFavImgView release];
        
        NSString* tFavStr = [tInDic objectForKey:@"favorite"];
        if (![[tInDic objectForKey:@"favorite"] isKindOfClass:[NSString class]]) {
            tFavStr = [NSString stringWithFormat:@"%d",[[tInDic objectForKey:@"favorite"] intValue]];
        }
        CGSize aFSize = [tFavStr sizeWithFont:tBoldFont];
        aFSize.width +=6;
        UILabel* tFavLab = [[UILabel alloc] initWithFrame:CGRectMake(aSize.width+32, 7+tOffsetHeight, aFSize.width, 16)];
        tFavLab.tag = 30000+tBttTag;//add by Scott
        tFavLab.text =tFavStr;
        [tFavLab setFont:tBoldFont];
        [tFavLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tTextView addSubview:tFavLab];
        tFavLab.textAlignment = UITextAlignmentLeft;
        [tFavLab release];
        tComPosX+=(aFSize.width+8);
        
        UIImageView* tComImgView=[[UIImageView alloc] initWithImage:_CommentPL];
        tComImgView.frame =CGRectMake(tComPosX-14, 10+tOffsetHeight, 10, 10);
        [tTextView addSubview:tComImgView];
        [tComImgView release];
        
        NSString* tComStr = [tInDic objectForKey:@"comment"];
        if (![[tInDic objectForKey:@"comment"] isKindOfClass:[NSString class]]) {
            tComStr = [NSString stringWithFormat:@"%d",[[tInDic objectForKey:@"comment"] intValue]];
        }
        CGSize aCComSize = [tComStr sizeWithFont:tBoldFont];
        aCComSize.width +=1;
        UILabel* tComLab = [[UILabel alloc] initWithFrame:CGRectMake(tComPosX, 7+tOffsetHeight, aCComSize.width, 16)];
        tComLab.text =tComStr;
        [tComLab setFont:tBoldFont];
        [tComLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tTextView addSubview:tComLab];
        tComLab.textAlignment = UITextAlignmentLeft;
        [tComLab release];

        
        
        UIButton* tZhuanCaiBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tZhuanCaiBtt.frame =CGRectMake(0, tHeight+25+tOffsetHeight, 40, 15);
        tZhuanCaiBtt.tag =tBttTag;
        [tZhuanCaiBtt setTitle:@"转采" forState:UIControlStateNormal];
        [tZhuanCaiBtt setTitleColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1] forState:UIControlStateNormal];
        [tZhuanCaiBtt.titleLabel setFont:[UIFont boldSystemFontOfSize:11]];
        [tZhuanCaiBtt addTarget:self action:@selector(toZhuanCai:) forControlEvents:UIControlEventTouchUpInside];
        [tCustomBtt addSubview:tZhuanCaiBtt];
        
        UILabel* tDot = [[UILabel alloc] initWithFrame:CGRectMake(34, tHeight+25+tOffsetHeight, 5, 16)];
        tDot.text =@"•";
        [tDot setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tCustomBtt addSubview:tDot];
        [tDot release];

        
        UIButton* tLikeBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tLikeBtt.tag =tBttTag;
        if (tIsLike == 0) {
            tLikeBtt.frame =CGRectMake(36, tHeight+25+tOffsetHeight, 40, 15);
            [tLikeBtt setTitle:@"喜欢" forState:UIControlStateNormal];
        } else {
            tLikeBtt.frame =CGRectMake(36, tHeight+25+tOffsetHeight, 70, 15);
            [tLikeBtt setTitle:@"取消喜欢" forState:UIControlStateNormal];
        }
        
        [tLikeBtt setTitleColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1] forState:UIControlStateNormal];
        [tLikeBtt.titleLabel setFont:[UIFont boldSystemFontOfSize:11]];
        [tLikeBtt addTarget:self action:@selector(toDirectLike:) forControlEvents:UIControlEventTouchUpInside];
        [tCustomBtt addSubview:tLikeBtt];
        
//        UILabel* tWordLab =[[UILabel alloc] initWithFrame:CGRectMake(8, 54, WidthMax-16, 15)];
//        [tWordLab setFont:[UIFont boldSystemFontOfSize:14]];
//        [tWordLab setBackgroundColor:[UIColor clearColor]];
//        [tWordLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
//        [tWordLab setText:@"转采  喜欢"];
//        [tTextView addSubview:tWordLab];
//        [tWordLab release];
        
        CALayer* tLineLayer = [CALayer layer];
        tLineLayer.frame= CGRectMake(0, 47+tOffsetHeight, WidthMax, 1);
        [tLineLayer setBackgroundColor:[UIColor colorWithRed:218/255.f green:218/255.f blue:218/255.f alpha:1].CGColor];
        [tTextView.layer addSublayer:tLineLayer];
        
        AsyncImageView* tUseAsyImg = [[AsyncImageView alloc] initWithFrame:CGRectMake(4, tHeight+53+tOffsetHeight, 25, 25)];
        tUseAsyImg.m_BoolSetImage =YES;
        tUseAsyImg._imageRequestURL = [tInDic objectForKey:@"avatar"];
        tUseAsyImg._numStateRequested = need_Request;
        [tCustomBtt addSubview:tUseAsyImg];
        [tUseAsyImg customLoadImageFromURL];
        [tUseAsyImg release];
        
        UIButton* tUseImgView =[UIButton buttonWithType:UIButtonTypeCustom];
        //[tUseImgView setBackgroundImage:_UserIcon forState:UIControlStateNormal];
        [tUseImgView addTarget:self action:@selector(bttToShowUserInfo:) forControlEvents:UIControlEventTouchUpInside];
        tUseImgView.frame =CGRectMake(4, tHeight+53+tOffsetHeight, 25, 25);
        tUseImgView.tag =tBttTag;
        [tCustomBtt addSubview:tUseImgView];
        
        UILabel* tNameLab =[[UILabel alloc] initWithFrame:CGRectMake(36, 51+tOffsetHeight, WidthMax-40, 15)];
        [tNameLab setBackgroundColor:[UIColor clearColor]];
        [tNameLab setFont:[UIFont systemFontOfSize:8]];
        [tNameLab setTextColor:[UIColor  blackColor]];
        [tNameLab setText:[tInDic objectForKey:@"user_nickname"]];
        [tTextView addSubview:tNameLab];
        [tNameLab release];
        
        UILabel* tTitleLab =[[UILabel alloc] initWithFrame:CGRectMake(36, 63+tOffsetHeight, WidthMax-40, 15)];
        [tTitleLab setBackgroundColor:[UIColor clearColor]];
        [tTitleLab setFont:[UIFont systemFontOfSize:8]];
        [tTitleLab setTextColor:[UIColor colorWithRed:136/255.f green:136/255.f blue:136/255.f alpha:1]];
        [tTitleLab setText:[tInDic objectForKey:@"collect"]];
        [tTextView addSubview:tTitleLab];
        [tTitleLab release];
        
        UIButton* tCollectBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tCollectBtt.frame =CGRectMake(36, tHeight+63+tOffsetHeight, WidthMax-40, 15);
        tCollectBtt.tag =tBttTag;
        [tCollectBtt addTarget:self action:@selector(toShowCollect:) forControlEvents:UIControlEventTouchUpInside];
        [tCustomBtt addSubview:tCollectBtt];

        tBttTag++;
    }
    int tMaxScrollH =_SearchLeftH;
    if (_SearchRightH > tMaxScrollH) {
        tMaxScrollH =_SearchRightH;
    }
    [_SearchContentSView setContentSize:CGSizeMake(320, tMaxScrollH)];
    [self scrollViewDidScroll:_SearchContentSView];
}

//搜索结果 专辑 显示
-(void) searchResCollectViewShow:(NSArray*)f_CollectArr
{
    int tBttTag = [_SearchContentDicArr count];
    [_SearchContentDicArr addObjectsFromArray:f_CollectArr];
    
    UIImage* tLineImg =[UIImage imageNamed:@"collect_footer.png"];
    UIFont* tTitleFont =[UIFont systemFontOfSize:11];
    
    for (NSDictionary* tInDic in f_CollectArr) {
        UIButton* tCustomBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        tCustomBtt.tag = tBttTag;
        [tCustomBtt addTarget:self action:@selector(bttToShowPBL:) forControlEvents:UIControlEventTouchUpInside];
        tCustomBtt.frame =CGRectMake(10+155*(tBttTag%2), _SearchLeftH, 145, CollectH);
        [tCustomBtt setBackgroundColor:[UIColor whiteColor]];
        CALayer* tLineLayer = [CALayer layer];
        tLineLayer.frame =CGRectMake(0, CollectH-5, 145, 5);
        tLineLayer.contents =(id)tLineImg.CGImage;
        [tCustomBtt.layer addSublayer:tLineLayer];
        [_SearchContentSView addSubview:tCustomBtt];
        
        NSArray* tCollectImgs= [tInDic objectForKey:@"image"];
        int tImgIndex = 0;
        for (NSString* tImgDic in tCollectImgs) {
            PBLAsyncImageView* tAsyImg =[[PBLAsyncImageView alloc] initWithFrame:CGRectMake(10+155*(tBttTag%2)+2+tImgIndex%2*70, _SearchLeftH+2+tImgIndex/2*70, 70, 70)];
            
            [tAsyImg setBackgroundColor:[UIColor colorWithRed:183/255.f green:185/255.f blue:183/255.f alpha:1.0]];
            
            NSString* tImgURL =tImgDic;
            tAsyImg._imageRequestURL =tImgURL;
            tAsyImg._numStateRequested =need_Request;
            tAsyImg.m_BoolSetImage =YES;
            tAsyImg.m_FloderIndex = -1;
            tAsyImg.m_AsyTag = tBttTag;
            tAsyImg.userInteractionEnabled =NO;
            
            [_SearchContentSView addSubview:tAsyImg];
            
            [_SearchViewsArr addObject:tAsyImg];
            [tAsyImg release];
            tImgIndex++;
        }
        
        CGSize tTitleSize =[[tInDic objectForKey:@"title"] sizeWithFont:tTitleFont];
        if (tTitleSize.width > 114) {
            tTitleSize.width =114;
        }
        UILabel* tTitelLab =[[UILabel alloc] initWithFrame:CGRectMake(4, 150, tTitleSize.width+2, 20)];
        [tTitelLab setBackgroundColor:[UIColor clearColor]];
        [tTitelLab setText:[tInDic objectForKey:@"title"]];
        [tTitelLab setTextColor:[UIColor blackColor]];
        [tTitelLab setFont:tTitleFont];
        [tCustomBtt addSubview:tTitelLab];
        [tTitelLab release];
        
        UILabel* tNumLab =[[UILabel alloc] initWithFrame:CGRectMake(4+tTitleSize.width+6, 150,70, 20)];
        [tNumLab setBackgroundColor:[UIColor clearColor]];
        [tNumLab setText:[tInDic objectForKey:@"count"]];
        [tNumLab setTextColor:[UIColor grayColor]];
        [tNumLab setFont:tTitleFont];
        [tCustomBtt addSubview:tNumLab];
        [tNumLab release];
        
        if (tBttTag%2 == 1) {
            _SearchLeftH+=CollectH+CollectLineH;
        }
        tBttTag++;
    }
    if (_SearchLeftH <= _SearchContentSView.frame.size.height) {
        [_SearchContentSView setContentSize:CGSizeMake(320, _SearchContentSView.frame.size.height+1)];
    }else{
        [_SearchContentSView setContentSize:CGSizeMake(320, _SearchLeftH)];
    }
    [_SearchContentSView setContentSize:CGSizeMake(320, _SearchLeftH)];
    [self scrollViewDidScroll:_SearchContentSView];
}

//搜索结果 人儿 显示
-(void) searchResUserViewShow:(NSArray*)f_UserArr
{
    int tBttTag = [_SearchContentDicArr count];
    [_SearchContentDicArr addObjectsFromArray:f_UserArr];
    
    
    for (NSDictionary* tInDic in f_UserArr) {        
        CALayer* tLineLayer =[CALayer layer];
        tLineLayer.frame = CGRectMake(0, _SearchLeftH+UserCellH-1, 320, 1);
        [tLineLayer setBackgroundColor:[UIColor colorWithRed:163/255.f green:163/255.f blue:163/255.f alpha:1].CGColor];
        [_SearchContentSView.layer addSublayer:tLineLayer];
        
        PBLAsyncImageView* tAsyImg =[[PBLAsyncImageView alloc] initWithFrame:CGRectMake(4, _SearchLeftH+3, 34, 34)];
        
        [tAsyImg setBackgroundColor:[UIColor colorWithRed:183/255.f green:185/255.f blue:183/255.f alpha:1.0]];
        
        NSString* tImgURL =[tInDic objectForKey:@"avatar"];
        tAsyImg._imageRequestURL =tImgURL;
        tAsyImg._numStateRequested =need_Request;
        tAsyImg.m_BoolSetImage =YES;
        tAsyImg.m_FloderIndex = -1;
        tAsyImg.m_AsyTag = tBttTag;
        tAsyImg.userInteractionEnabled =NO;
        
        [_SearchContentSView addSubview:tAsyImg];
        
        [_SearchViewsArr addObject:tAsyImg];
        [tAsyImg release];
        
        UILabel* tNameLab =[[UILabel alloc] initWithFrame:CGRectMake(50, _SearchLeftH+12, 200, 16)];
        [tNameLab setBackgroundColor:[UIColor clearColor]];
        [tNameLab setText:[tInDic objectForKey:@"nickname"]];
        [tNameLab setFont:[UIFont systemFontOfSize:14]];
        [_SearchContentSView addSubview:tNameLab];
        [tNameLab release];
        
        UIButton* tShowRen=[UIButton buttonWithType:UIButtonTypeCustom];
        tShowRen.tag =tBttTag;
        [tShowRen addTarget:self action:@selector(showRen:) forControlEvents:UIControlEventTouchUpInside];
        tShowRen.frame = CGRectMake(0, _SearchLeftH, 240, 42);
        [_SearchContentSView addSubview:tShowRen];
        
        UIButton* tBttFollow=[UIButton buttonWithType:UIButtonTypeCustom];
        tBttFollow.layer.cornerRadius =4.f;
        tBttFollow.layer.borderWidth =1;
        tBttFollow.frame =CGRectMake(254, _SearchLeftH+7, 52, 26);
        tBttFollow.layer.borderColor = [UIColor colorWithRed:153/255.f green:153/255.f blue:153/255.f alpha:1].CGColor;
        [tBttFollow setBackgroundColor:[UIColor whiteColor]];
        [tBttFollow.titleLabel setFont:[UIFont systemFontOfSize:11]];
        int tFollowValue =[[tInDic objectForKey:@"isfollowed"] intValue];
        if (tFollowValue == 0) {
            [tBttFollow setTitle:@"关注" forState:UIControlStateNormal];
        }else{
            [tBttFollow setTitle:@"取消关注" forState:UIControlStateNormal];
        }
        
        [tBttFollow setTitleColor:[UIColor colorWithRed:100/255.f green:100/255.f  blue:100/255.f  alpha:1] forState:UIControlStateNormal];
        [tBttFollow addTarget:self action:@selector(guanzhu:) forControlEvents:UIControlEventTouchUpInside];
        [_SearchContentSView addSubview:tBttFollow];
        
        _SearchLeftH+=UserCellH;
        tBttTag++;
    }
    if (_SearchLeftH <= _SearchContentSView.frame.size.height) {
        [_SearchContentSView setContentSize:CGSizeMake(320, _SearchContentSView.frame.size.height+1)];
    }else{
        [_SearchContentSView setContentSize:CGSizeMake(320, _SearchLeftH)];
    }
    [self scrollViewDidScroll:_SearchContentSView];
}


-(void) showRen:(UIButton*)f_sender
{
    NSDictionary* tDic = [_SearchContentDicArr objectAtIndex:f_sender.tag];

    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    OwnViewController* tNextVC = [[OwnViewController alloc] initUesrID:[tDic objectForKey:@"id"]];
    tNextVC.navigationItem.hidesBackButton =YES;
    [self.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
    
}

-(void)headPressed
{
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    OwnViewController* tNextVC = [[OwnViewController alloc] initUesrID:_CollectUserIDStr];
    tNextVC.navigationItem.hidesBackButton =YES;
    [self.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}

-(void) guanzhu:(UIButton*)f_sender
{
    MainTabBarController* tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
    if (tMainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
        return;
    }
    NSDictionary* tDic = [_SearchContentDicArr objectAtIndex:f_sender.tag];
    NSString* url =nil;
    if ([f_sender.titleLabel.text isEqualToString:@"关注"]) {
        
        url = [NSString stringWithFormat:@"%@?app=userNew&act=follow&type=%d&user_id=%@&target_user_id=%d",RequestMainURL,1,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[[tDic objectForKey:@"id"] intValue]];
    }else{
        url = [NSString stringWithFormat:@"%@?app=userNew&act=follow&type=%d&user_id=%@&target_user_id=%d",RequestMainURL,2,[tMainTabBar.m_UserDic objectForKey:@"user_id"],[[tDic objectForKey:@"id"] intValue] ];
    }

    NSLog(@"url = %@",url);
    [self addHudLoad];
    ASIHTTPRequest* tGetRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
    //    [tGetRequest setTimeOutSeconds:20.f];
    tGetRequest.m_Tag = (int) f_sender;
    [tGetRequest setDelegate:self];
    [tGetRequest setDidFailSelector:@selector(followFail:)];
    [tGetRequest setDidFinishSelector:@selector(followOk:)];
    [tGetRequest startAsynchronous];
}
- (void)followFail:(ASIHTTPRequest *)request;
{
    [self hudWasHidden:nil];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:@"网络错误请稍后再试" isCue:YES delayTime:3.0f];
}
- (void)followOk:(ASIHTTPRequest *)request;
{
    NSError* tError;
    NSString* tReqStr = [request responseString];
    NSLog(@"ads json data =%@",tReqStr);
    NSData *jsonData = [tReqStr dataUsingEncoding:NSUTF32BigEndianStringEncoding];
	NSDictionary *tDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&tError] ;
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if (tDictionary == nil) {
        [tAppDel showWithCustomView:@"提示" detailText:@"获得数据错误" isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [_PBLRequest setDelegate:nil];
        [_PBLRequest release];
        _PBLRequest= nil;
        [_BottomNot hide:YES];
        return;
    }
    int tErrorCode= [[tDictionary objectForKey:@"errorCode"] intValue];
    if (tErrorCode != 0) {
        [tAppDel showWithCustomView:@"提示" detailText:[tDictionary objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
        [self hudWasHidden:nil];
        [_PBLRequest setDelegate:nil];
        [_PBLRequest release];
        _PBLRequest= nil;
        [_BottomNot hide:YES];
        return;
    }
    UIButton* tFollowBtt = (UIButton*)request.m_Tag;
    if ([tFollowBtt.titleLabel.text isEqualToString:@"关注"]) {
        [tFollowBtt setTitle:@"取消关注" forState:UIControlStateNormal];
        [tAppDel showWithCustomView:@"关注成功" detailText:@"" isCue:NO delayTime:2.0f];
    }else{
        [tFollowBtt setTitle:@"关注" forState:UIControlStateNormal];
        [tAppDel showWithCustomView:@"取消关注成功" detailText:@"" isCue:NO delayTime:2.0f];
    }
    [self hudWasHidden:nil];
}
@end

